//
//  ViewController.m
//  JinduExample
//
//  Created by tyndog on 2017/1/16.
//  Copyright © 2017年 GT. All rights reserved.
//

#import "ViewController.h"
#import "GTProgressView.h"
#import "CoreDemo.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet GTProgressView *progressView;

@property (weak, nonatomic) IBOutlet CoreDemo *demoView;
/** */
@property (strong, nonatomic) dispatch_source_t timer;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    

    
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    static CGFloat count = 0.0f;
    
//    [self.progressView setProgress:count];
    _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());
    dispatch_source_set_timer(_timer, DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC, 0.1 * NSEC_PER_SEC);
    dispatch_source_set_event_handler(_timer, ^{
        count += 0.05f;
        if (count >= 1.0f) {
            count = 1.0f;
        }
        [self.progressView setProgress:count];
        [self.demoView setProgress:count];
        if (count >= 1.0f) {
            _timer = nil;
        }
    });
    dispatch_resume(_timer);
}

@end
